﻿<!--
  This source code file contains modifications authored by Microsoft Corporation. 
  All such modifications are copyright (c) Microsoft Corporation. All rights reserved.
-->

<rules>
  <rule id="Entry.Core.1009" category="core" target="entry" specificationsection ="2.2.6.2.2" v4specificationsection="6.4" v4specification="odataatom" requirementlevel="should" format="atom">
    <description>An &lt;atom:link&gt; element SHOULD be included, which contains an atom:rel="edit" or atom:rel="self" attribute.</description>
    <action processor="rng">
      <grammar xmlns="http://relaxng.org/ns/structure/1.0" xmlns:atom="http://www.w3.org/2005/Atom">
        <start>
          <element>
            <anyName />
            <ref name="anyAttributes" />
            <interleave>
              <element name="atom:link">
                <attribute name="rel">
                  <choice>
                    <value>self</value>
                    <value>edit</value>
                  </choice>
                </attribute>
                <ref name="anyAttributes_other_than_atom_rel" />
              </element>
              <zeroOrMore>
                <choice>
                  <!-- Any element that is not atom:link. -->
                  <ref name="anyElement_other_than_atom_link" />
                  <!-- Any element that is atom:link yet with attribute rel not equal to self or edit. -->
                  <ref name="anyElement_of_atom_link_with_attribute_rel_without_value_self_or_edit" />
                </choice>
              </zeroOrMore>
            </interleave>
          </element>
        </start>
        <define name="anyAttributes">
          <zeroOrMore>
            <choice>
              <attribute>
                <anyName />
              </attribute>
            </choice>
          </zeroOrMore>
        </define>
        <define name="anyAttributes_other_than_atom_rel">
          <zeroOrMore>
            <choice>
              <attribute>
                <anyName>
                  <except>
                    <name>rel</name>
                  </except>
                </anyName>
              </attribute>
            </choice>
          </zeroOrMore>
        </define>
        <define name="anyAttributes_other_than_atom_rel_with_value_self_or_edit">
          <zeroOrMore>
            <choice>
              <attribute>
                <anyName>
                  <except>
                    <name>rel</name>
                  </except>
                </anyName>
              </attribute>
              <attribute>
                <name>rel</name>
                <data type="token">
                  <except>
                    <value>self</value>
                    <value>edit</value>
                  </except>
                </data>
              </attribute>
            </choice>
          </zeroOrMore>
        </define>
        <define name="anyElement">
          <element>
            <anyName />
            <zeroOrMore>
              <choice>
                <attribute>
                  <anyName />
                </attribute>
                <text />
                <ref name="anyElement" />
              </choice>
            </zeroOrMore>
          </element>
        </define>
        <define name="anyElement_other_than_atom_link">
          <element>
            <choice>
              <anyName>
                <except>
                  <nsName ns="http://www.w3.org/2005/Atom" />
                </except>
              </anyName>
              <nsName ns="http://www.w3.org/2005/Atom">
                <except>
                  <name>atom:link</name>
                </except>
              </nsName>
            </choice>
            <ref name="anyAttributes" />
            <text />
            <zeroOrMore>
              <ref name="anyElement" />
            </zeroOrMore>
          </element>
        </define>
        <define name="anyElement_of_atom_link_with_attribute_rel_without_value_self_or_edit">
          <element name="atom:link">
            <ref name="anyAttributes_other_than_atom_rel_with_value_self_or_edit" />
            <text />
            <zeroOrMore>
              <ref name="anyElement" />
            </zeroOrMore>
          </element>
        </define>
      </grammar>
    </action>
    <errormessage>An &lt;atom:link&gt; element SHOULD be included, which contains an atom:rel="edit" or atom:rel="self" attribute.</errormessage>
  </rule>
</rules>